import pagination from '../../components/common/pageComponent'
import instance from '@/api/index.js'

export default {
  name: 'manuallyCreateOrder',
  data() {
    return {
      disabled: false,//店铺可选标识
      accountDisabled: false,//收款账号可选标识
      orderInfo: {//订单信息
        platformOrderId: null,//平台交易号
        orderTime: '',//订单时间
        orderChannel: [],//订单渠道
        orderChannelSelect: null,//订单渠道选择
        store: [],//店铺
        storeSelect: null,//店铺选择
        loansReceivable: '',//应收货款
        thePostageReceivable: null,//应收邮资
        costOfPlatform: '',//平台费用
        transitionFee: null,//转账费
        shroffAccountNum: '',//收款账号
        payTime: '',//付款时间
        record:null,//销售记录号
        treatMoney:null,//退补金额
        billCode:'',//物流单号
        logistics:'',//物流渠道
        customsNo:null,//申报关区代码
        payNo:null,//支付交易流水号
        currency:'',//货币代码
        treatType:'',
        orderType: 1,
        assbillNo:'',
        bigPackageNo:'',
        smallPackageNo:'',
        storeName:''
      },
      customerInfo: {//客户信息
        buyerId: '',//客户ID buyerId
        firstName: '',//客户姓名
        lastName: '',//客户姓名
        receiverFirstName:'',//
        receiverLastName:'',//
        contactNumFrist: null,//联系电话1
        contactNumSec: null,//联系电话2
        contactEmail: '',//联系邮箱
        homeCountry: '',//所属国家
        homeCountrySelectCode: '',//所属国家选择 code
        homeCountrySelectName:'',//所属国家选择 name
        provincialState: '',//省/洲
        city: '',//所属城市
        postcode: null,//邮编
        houseNum: '',//门牌号
        mailingAddress: '',//邮寄地址
        standbyAddress: ''//备用地址
      },
      message:'',//平台留言说明
      remark:'',//订单备注
      productInfo: {//商品信息
        productList: [],//商品列表
      },
      currencyList:[],//币种列表
      checkProduct: [],
      checkedNames:[],
      orderDetailInfo: {
        platformOrderId: '',
        channel: '',
        account: '',
        total: null,
        storeId: null,
        payTimeStr: '',
        buyerId: '',
        name: '',
        phone: '',
        otherPhone: '',
        country: '',
        countryName: '',
        state: '',
        city: '',
        postalCode: '',
        street1: '',
        street2: '',
        mail: '',
        houseNumber: '',
        platformFee: '',
        transferFee: '',
        remark: '',
        orderCreated: '',
        shipping: null,
        items: []
      },
      addPdocutcList: [],
      productParams: {},
      pages: {
        total: 0,
        current: 1,
        display: 10,
      },
      indexProduct: '',//获取下标
      errorShow: false,//错误显示
      errorMsg: '',//错误信息
      errorTitle: '',//错误提示标题
      errorClass: false,//错误样式
      accoutList:[],
      styleObj:{background:'#F5F7FA'},
      retreatingType:[],
      modal:'',
      orderIdEdited:'',
      isEdited:false,
      infoShow:true,
      platShow:true,
      markShow:true,
      clientShow:true,
      goodsShow:true,
      logisticsList:[]
    }

  },
  methods: {
    /*选择国家之后赋值国家名称*/
    handleDealCountry(){
      this.customerInfo.homeCountry.forEach((item,index)=>{
        if (item.code == this.homeCountrySelectCode){
           this.homeCountrySelectName = item.name;
        }
      })
    },
    //获取平台列表或者下拉框
    getPlatFormList: function () { //获取平台列表或者下拉框
      let vm = this;
      vm.disabled = true;
      vm.accountDisabled = true;
      instance({
        method: 'post',
        url: '/v1/author/getPlatFrom'
      }).then(function (data) {
        if (data.data.success) {
          vm.orderInfo.orderChannel = data.data.data;
        }
      });
    },
        //店铺变化收款账号也变化
    changeShop: function () {
      let vm = this;
      if (!vm.orderInfo.storeSelect) {
        vm.accountDisabled = true;
        vm.accoutList = [];
        return;
      }
      vm.accountDisabled = false;
      for(let i = 0; i < vm.orderInfo.store.length; i++){
        if(vm.orderInfo.storeSelect == vm.orderInfo.store[i].id){
          vm.accoutList = vm.orderInfo.store[i].accounts;
        }
      }
    },
    //订单渠道变化店铺也变化
    changeChanner: function () {
      let vm = this;
      if (!vm.orderInfo.orderChannelSelect) {
        vm.disabled = true
        this.modal = false
        return;
      }
      this.modal = true
      vm.disabled = false;
      vm.getStore(vm.orderInfo.orderChannelSelect);
    },

    //提交订单
    submitOrderDetail: function (sourceFlag) {
      let vm = this;
      //校验数据；
      if (!vm.orderInfo.platformOrderId) {
        vm.$alert('请输入订单编号！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }else if (vm.orderInfo.platformOrderId.length > 30) {
        vm.$alert('订单编号字段值应该小于31位，请确认！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }


      if (!vm.orderInfo.currency) {
        vm.$alert('请选择币种！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
/*      if (!vm.orderInfo.transitionFee) {
        vm.$alert('请输入转会费！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }*/
      if (!vm.orderInfo.shroffAccountNum) {
        vm.$alert('请输入收款账号！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
  /*    if (!vm.orderInfo.treatMoney) {
        vm.$alert('请输入退补金额！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }*/
      if (!vm.customerInfo.contactEmail) {
        vm.$alert('请输入联系邮箱！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
  /*    if (!vm.customerInfo.houseNum) {
        vm.$alert('请输入门牌号！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }*/

      if (!vm.orderInfo.orderTime) {
        vm.$alert('请输入订单时间！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.orderInfo.orderChannelSelect) {
        vm.$alert('请选择订单渠道！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.orderInfo.storeSelect) {
        vm.$alert('请选择店铺！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.orderInfo.loansReceivable) {
        vm.$alert('请输入订单金额！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (vm.orderInfo.orderType == 1 || vm.orderInfo.orderType == 2) {
        if(!vm.orderInfo.logistics) {
          vm.$alert('请选择物流渠道！', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
      }
      if (vm.orderInfo.orderType == 1) {
        if(!vm.orderInfo.payNo) {
          vm.$alert('请输入支付交易流水号！', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
      }

      if (vm.orderInfo.customsNo && vm.orderInfo.customsNo.length != 4) {
        vm.$alert('申报关区代码字段值应该为4位，请确认！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (vm.orderInfo.assbillNo && vm.orderInfo.assbillNo.length > 32) {
        vm.$alert('分运单号字段值应该小于33位，请确认！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }

      if (vm.orderInfo.orderType == 2) {
        if(!vm.orderInfo.billCode) {
          vm.$alert('请输入物流单号！', '提示', {
            confirmButtonText: '确定',
          });
          return;
        }
      }
      if (!vm.customerInfo.buyerId) {
        vm.$alert('请输入客户ID！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.customerInfo.firstName) {
        vm.$alert('请输入客户姓名！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.customerInfo.lastName) {
        vm.$alert('请输入客户姓名！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.customerInfo.receiverFirstName) {
        vm.$alert('请输入收货人！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.customerInfo.receiverLastName) {
        vm.$alert('请输入收货人！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if(!vm.customerInfo.contactNumFrist) {
        vm.$alert('请输入联系电话！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (!vm.productInfo.productList || vm.productInfo.productList.length == 0) {
        vm.$alert('请添加商品！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      } else {

        for (var k = 0; k < vm.productInfo.productList.length; k++) {
          let product = vm.productInfo.productList[k];
          if (!product.sku) {
            vm.$alert('请输入平台sku！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
          if (!product.erpSku) {
            vm.$alert('请输入系统sku！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
          if (!product.price) {
            vm.$alert('请输入商品单价！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
          if (!product.quantity) {
            vm.$alert('请输入发货数量！', '提示', {
              confirmButtonText: '确定',
            });
            return;
          }
        }
      }
      if(!vm.customerInfo.homeCountrySelectCode) {
        vm.$alert('请输入所属国家！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
 /*     if(!vm.customerInfo.provincialState) {
        vm.$alert('请输入省/州！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }*/
 /*     if(!vm.customerInfo.city) {
        vm.$alert('请输入所属城市！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }*/
      if(!vm.customerInfo.mailingAddress) {
        vm.$alert('请输入邮寄地址！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }



      //验证完毕组合数据   platformOrderId
      vm.orderDetailInfo.platformOrderId = vm.orderInfo.platformOrderId;// 订单编号
      vm.orderDetailInfo.channel = vm.orderInfo.orderChannelSelect;// 订单渠道
      vm.orderDetailInfo.total = vm.orderInfo.loansReceivable;// 应收货款
      vm.orderDetailInfo.storeId = vm.orderInfo.storeSelect;// 商店
      vm.orderDetailInfo.payTimeStr = vm.orderInfo.payTime;// 付款时间
      vm.orderDetailInfo.orderCreated = vm.orderInfo.orderTime;// 订单时间
      vm.orderDetailInfo.buyerId = vm.customerInfo.buyerId;// 客户id
      vm.orderDetailInfo.customerFirstName = vm.customerInfo.firstName;// 名
      vm.orderDetailInfo.customerLastName = vm.customerInfo.lastName;// 姓
      vm.orderDetailInfo.receiverFirstName = vm.customerInfo.receiverFirstName;
      vm.orderDetailInfo.receiverLastName = vm.customerInfo.receiverLastName;
      vm.orderDetailInfo.phone = vm.customerInfo.contactNumFrist;// 联系电话
      vm.orderDetailInfo.otherPhone = vm.customerInfo.contactNumSec;// 联系电话
      vm.orderDetailInfo.country = vm.customerInfo.homeCountrySelectCode;// 国家
      vm.orderDetailInfo.countryName = vm.customerInfo.homeCountrySelectName;// 国家名称
      vm.orderDetailInfo.state = vm.customerInfo.provincialState;// 省/州
      vm.orderDetailInfo.city = vm.customerInfo.city;// 城市
      vm.orderDetailInfo.postalCode = vm.customerInfo.postcode;// 邮编 postalCode
      vm.orderDetailInfo.street1 = vm.customerInfo.mailingAddress;// 邮寄地址
      vm.orderDetailInfo.street2 = vm.customerInfo.standbyAddress;// 备用地址
      vm.orderDetailInfo.platformFee = vm.orderInfo.costOfPlatform;// 平台服务费
      vm.orderDetailInfo.transferFee = vm.orderInfo.transitionFee;// 转账费
      vm.orderDetailInfo.account = vm.orderInfo.shroffAccountNum;// 收款账户
      vm.orderDetailInfo.mail = vm.customerInfo.contactEmail;// 邮箱
      vm.orderDetailInfo.houseNumber = vm.customerInfo.houseNum;// 门牌号
      vm.orderDetailInfo.postage = vm.orderInfo.thePostageReceivable;// 运费
      vm.orderDetailInfo.message = this.message;
      vm.orderDetailInfo.remark = this.remark;
     /* vm.orderDetailInfo.items.splice(0);*/
      vm.orderDetailInfo.items=[];
 /*     vm.productInfo.productList.forEach(function (product, index) {
     /!*   let item = {
          price: product.unitPrice,//单价
          sku: product.ebaySKU,//sku
          goodsId: product.goodsId, //系统商品id
          quantity: product.shipmentsNum, //数量
          stockId: product.warehouseSelect //仓库id
        }*!/
      /!*  vm.orderDetailInfo.items.push(item);*!/
      })*/
      vm.orderDetailInfo.items = vm.productInfo.productList;
      Object.assign( vm.orderDetailInfo,vm.productInfo,vm.orderInfo,vm.customerInfo)
      let api = '';
      if (this.isEdited){
        api = `/v1/order/confirm/${this.orderIdEdited}`
      }else {
        api = '/v1/order/create'
      }
      instance({
        method: 'post',
        url: api,
        data: vm.orderDetailInfo
      }).then(function (data) {
        if (data.data.success) {
          vm.$alert(vm.orderIdEdited ? '编辑订单成功 ':'新增订单成功！', '提示', {
            confirmButtonText: '确定',
            callback: action => {
              if (sourceFlag == 1){
                vm.$router.back();
              }
            }
          });

          //后清空数据
          vm.message = '';
          vm.remark = '';
          for (var key in vm.orderInfo) {
            if (key != 'orderChannel' && key != 'store') {
              if (key == 'orderType'){
                vm.orderInfo[key] = 1;
              } else {
                vm.orderInfo[key] = '';
              }

            }
          }
          for (var key in vm.customerInfo) {
            if (key !='homeCountry'){
              vm.customerInfo[key] = '';
            }
          }
          vm.productInfo.productList.splice(0);
        } else {
          vm.$alert('添加手工订单失败！', '提示', {
            confirmButtonText: '确定',
          });
        }
      })
    },
    //继续添加
    continueAddOrderDetail: function (souce) {
      let vm = this;
      //先提交订单
      this.submitOrderDetail(souce);

    },

    //定时信息提示
    setTime: function () {
      let vm = this;
      setTimeout(function () {
        vm.errorShow = false;
      }, 2500)
    },

    //关闭信息提示
    closeError: function () {
      this.errorShow = false;
    },

    //获取授权平台下的店铺
    getStore: function (_id) {
      let vm = this;
      instance({
        method: 'post',
        url: '/v1/author/getAuthorShopList',
        data: {
          id: _id,
          status: 1
        }
      }).then(function (data) {
        if (data.data.success) {
          vm.orderInfo.store = data.data.data;
        }
      })
    },

    //获取国家信息
    getCountry: function () {
      let vm = this;
      instance({
        method: 'post',
        url: 'v1/ebay/meta/country/getList',
      }).then(function (data) {
        console.log(data)
        if (data.data.success) {
          vm.customerInfo.homeCountry = data.data.data
        }
      })
    },

    //根据sku查仓库
    getStorage: function (_sku) {
      let vm = this;
      instance({
        method: 'post',
        url: '/v1/warehouse/getGoodsStockInfoList',
        data: {
          sku: _sku
        }
      }).then(function (data) {
      })
    },

    //添加商品
    addPdocutc: function () {
      let vm = this;
      let productObj = {quantity:'',erpSku:'',price:null,sku:''};
      vm.productInfo.productList.push(productObj);
      vm.productInfo.productList.forEach((item,index)=>{
        vm.productInfo.productList[index].quantity =item.quantity
      })
    },

    //删除商品
    deleteProduct: function (_index) {
      this.productInfo.productList.splice(_index, 1);
    },

    searchProduct(){
      let vm = this;
      vm.checkProduct = [];
      vm.productParams.rows = 5;
      vm.productParams.page = vm.pages.current;
      vm.pages.display = vm.productParams.rows;
      let api = `v1/goodsRelation/listGoods?page=${vm.pages.current}`
      if (this.productParams.erpSku) {
        api = api + `&erpSku=${this.productParams.erpSku}`
      }
      if(this.orderInfo.orderChannelSelect){
        api = api + `&channel=${this.orderInfo.orderChannelSelect}`
      } else {
        vm.$alert('请选择订单渠道！', '提示', {
          confirmButtonText: '确定',
        });
        return
      }
      instance({
        method: 'get',
        url: api
      }).then(function (data) {
        if (data.data.success) {
          vm.addPdocutcList = data.data.data.list;
            vm.pages.total = data.data.data.pages;
        }
      });
    },
    resetProduct(){
      let vm = this;
      vm.checkProduct = [];
      vm.productParams.rows = 5;
      vm.productParams.erpSku = '';
      vm.productParams.page = vm.pages.current;
      vm.pages.display = vm.productParams.rows;
      let api = `v1/goodsRelation/listGoods?page=${vm.pages.current}`
      if (this.productParams.erpSku) {
        api = api + `&erpSku=${this.productParams.erpSku}`
      }
      if(this.orderInfo.orderChannelSelect){
        api = api + `&channel=${this.orderInfo.orderChannelSelect}`
      } else {
        vm.$alert('请选择订单渠道！', '提示', {
          confirmButtonText: '确定',
        });
        return
      }
      instance({
        method: 'get',
        url: api
      }).then(function (data) {
        if (data.data.success) {
          vm.addPdocutcList = data.data.data.list;
          vm.pages.total = data.data.data.pages;
        }
      });
    },

    //选择产品
    chooseProduct: function (_index) {
      let vm = this;
      vm.checkProduct = [];
      vm.productParams.rows = 5;
      vm.productParams.erpSku = '';
      vm.productParams.page = vm.pages.current;
      vm.pages.display = vm.productParams.rows;
      console.log(vm.productParams)
      let api = `v1/goodsRelation/listGoods?page=${vm.pages.current}`
      if (this.productParams.erpSku) {
        api = api + `&erpSku=${this.productParams.erpSku}`
      }
      if(this.orderInfo.orderChannelSelect){
        api = api + `&channel=${this.orderInfo.orderChannelSelect}`
      } else {
        vm.$alert('请选择订单渠道！', '提示', {
          confirmButtonText: '确定',
        });
        return
      }
      instance({
        method: 'get',
        url: api,
      }).then(function (data) {
        if (data.data.success) {
          vm.addPdocutcList = data.data.data.list;
          vm.pages.total = data.data.data.pages;
          vm.indexProduct = _index;
        }
      });
    },

    // 获取分页
    pagechange: function (currentPage) {
      this.pages.current = currentPage;
      this.productParams.pages = currentPage;
      this.chooseProduct();
    },

    //保存
    submitProduct: function () {
      console.log(this.checkProduct)
      if (this.checkProduct.length == 0) {
        this.$alert('请选择一个商品！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      if (this.checkProduct.length > 1) {
        this.$alert('请选择一个商品！', '提示', {
          confirmButtonText: '确定',
        });
        return;
      }
      this.productInfo.productList[this.indexProduct].erpSku = this.checkProduct[0].erpSku;
      this.productInfo.productList[this.indexProduct].sku = this.checkProduct[0].sku;
      this.productInfo.productList[this.indexProduct].goodsId = this.checkProduct[0].id;
      let vm = this;
      instance({
        method: 'post',
        url: '/v1/warehouse/getGoodsStockInfoList',
        data: {
          sku: vm.checkProduct[0].sku
        }
      }).then(function (data) {
        if (data.data.success) {
          for (let i = 0; i < data.data.data.length; i++) {
            vm.productInfo.productList[vm.indexProduct].warehouse = data.data.data[i].stockInfoVOS;
          }
        }
      })
    },

    //选择发货仓库后仓库库存已发货数量比较
    chooseWh: function (_id) {
      let wh = this.productInfo.productList[this.indexProduct].warehouse;
      let index = wh.findIndex(function (item) {
        return item.whId == _id
      });
      let stockQty = this.productInfo.productList[this.indexProduct].warehouse[index]["stockQty"];
      this.productInfo.productList[this.indexProduct].stockQty = stockQty;
      let shipmentsNum = this.productInfo.productList[this.indexProduct].shipmentsNum;
      if (shipmentsNum > stockQty) {
        this.errorClass = false;
        this.errorShow = true;
        this.errorTitle = "发货仓库库位错误";
        this.errorMsg = "发货仓库库存少于发生数量，清重新选择";
        this.setTime();
        return;
      }
    },

    //选择发货仓库后仓库库存已发货数量比较
    blurShipmentsNum: function (_indexNum) {
      let stockQty = this.productInfo.productList[this.indexProduct].stockQty;
      let shipmentsNum = this.productInfo.productList[this.indexProduct].shipmentsNum;
      if (shipmentsNum > stockQty) {
        this.errorClass = false;
        this.errorShow = true;
        this.errorTitle = "发货仓库库位错误";
        this.errorMsg = "发货仓库库存少于发生数量，清重新选择";
        this.setTime();
        return;
      }
    },

    //添加库存商品
    addInventory: function (_obj) {
      let productObj = {};
      productObj.pic = _obj.pic;
      productObj.productInfo = _obj.productInfo;
      productObj.sku = _obj.sku;
      productObj.ebaySKU = '';
      productObj.unitPrice = '';
      productObj.warehouse = _obj.warehouse;
      productObj.warehouseSelect = '';
      productObj.shipmentsNum = '';
      productObj.stockQty = '';
      this.productInfo.productList.push(productObj);
      console.log(productObj)
    },
    closeBack(){
      this.$router.push(`/v1/order/list`)
    },
    getCurrency(){
     let api = '/v1/dict/currency';
      instance({
        method:'get',
        url:api
      }).then((res)=>{
        if (res.data.success){
          this.currencyList = res.data.data
        }
      })
    },
    //获取退补类型
    getRetreatingType() {
      let vm = this;
      instance.get('/v1/dict/charge').then(function (data) {
        vm.retreatingType = data.data.data;
      })
    },
    handleChoseChannel(flag){
      switch (flag) {
        case 1:
          return 'ebay';
          break;
        case 2:
          return 'Amazon';
          break;
        case 3:
          return 'magento';
          break;
        case 4:
          return '其他';
          break;
        default:
          return '其他'
          break;
      }
    },
    getDetail(id){
      let api = `/v1/order/get/${id}`;
      instance({
        method:'get',
        url:api
      }).then((res)=>{
        if (res.data.success){
            let result = res.data.data;
          this.orderInfo.platformOrderId = result.platformOrderId
          this.orderInfo.orderTime = result.orderCreated
          this.orderInfo.record = result.record
          this.orderInfo.currency = result.currency
          this.orderInfo.orderChannelSelect = result.channel
          this.getStore(this.orderInfo.orderChannelSelect);
          if (this.orderInfo.orderChannelSelect) {
            this.modal = true
          }else {
            this.modal = false
          }
          this.orderInfo.storeSelect = result.storeId
          this.orderInfo.loansReceivable = result.total
          this.orderInfo.thePostageReceivable = result.postage
          this.orderInfo.costOfPlatform = result.platformFee
          this.orderInfo.transitionFee = result.transferFee
          this.orderInfo.shroffAccountNum = result.account
          this.orderInfo.payTime = result.payTimeStr
          this.orderInfo.treatType = result.treatType
          this.orderInfo.treatMoney = result.treatMoney
          this.orderInfo.logistics = result.logistics
          this.orderInfo.billCode = result.billCode
          this.orderInfo.orderType = result.orderType
          this.orderInfo.customsNo = result.customsNo
          this.orderInfo.assbillNo = result.assbillNo
          this.orderInfo.bigPackageNo = result.bigPackageNo
          this.orderInfo.smallPackageNo = result.smallPackageNo
          this.orderInfo.payNo = result.payNo
          this.orderInfo.storeName = result.storeName
          this.message = result.message
          this.remark = result.remark
          this.customerInfo.buyerId = result.buyerId
          this.customerInfo.firstName = result.customerFirstName
          this.customerInfo.lastName = result.customerLastName
          this.customerInfo.receiverFirstName = result.receiverFirstName
          this.customerInfo.receiverLastName = result.receiverLastName
          this.customerInfo.contactNumFrist = result.phone
          this.customerInfo.contactNumSec = result.otherPhone
          this.customerInfo.contactEmail = result.mail
          this.customerInfo.homeCountrySelectCode = result.country
          this.customerInfo.provincialState = result.state
          this.customerInfo.city = result.city
          this.customerInfo.postcode = result.postalCode
          this.customerInfo.houseNum = result.houseNumber
          this.customerInfo.mailingAddress = result.street1
          this.customerInfo.standbyAddress = result.street2
          this.productInfo.productList = result.items || []
          this.changeShop();
        }
      })
    },
    getLogistics(){
      let api = '/v1/dict/logistics';
      instance({
        method:'get',
        url:api
      }).then((res)=>{
        if (res.data.success){
          this.logisticsList = res.data.data
        }
      })
    },
  },
  created() {
    //获取平台列表或者下拉框
    this.getPlatFormList();

    //获取授权平台下的店铺
    this.getStore(this.orderInfo.orderChannelSelect);

    //获取国家信息
    this.getCountry();

    //
    this.getStorage("SMK123456");
    this.getCurrency();
    this.getLogistics();
    this.getRetreatingType();
    this.orderIdEdited =  this.$route.query.orderId;
    if (this.orderIdEdited ) {
      this.isEdited = true;
      this.getDetail(this.orderIdEdited )
    }else {
      this.isEdited = false;
    }
  },
  computed: {
    platformOrderId() {
      return this.orderInfo.platformOrderId;
    },
    loansReceivable() {
      return this.orderInfo.loansReceivable;
    },
    thePostageReceivable() {
      return this.orderInfo.thePostageReceivable;
    },
    costOfPlatform() {
      return this.orderInfo.costOfPlatform;
    },
    transitionFee() {
      return this.orderInfo.transitionFee;
    },
    time() {
      return this.orderInfo.time;
    },
  },
  watch: {
    // platformTransactionNum: function () {
    //   this.orderInfo.platformTransactionNum = this.orderInfo.platformTransactionNum.replace(/[^0-9]/g, '');
    // },
    loansReceivable: function () {
      this.orderInfo.loansReceivable = this.orderInfo.loansReceivable.replace(/[^0-9\.]/g, '');
    },
    thePostageReceivable: function () {
      this.orderInfo.thePostageReceivable = this.orderInfo.thePostageReceivable.replace(/[^0-9\.]/g, '');
    },
    costOfPlatform: function () {
      this.orderInfo.costOfPlatform = this.orderInfo.costOfPlatform.replace(/[^0-9\.]/g, '');
    },
    transitionFee: function () {
      this.orderInfo.transitionFee = this.orderInfo.transitionFee.replace(/[^0-9\.]/g, '');
    },
    time: function () {
      this.orderInfo.payTime = this.orderInfo.payTime.replace(/[^0-9\.\-]/g, '');
      this.orderInfo.orderTime = this.orderInfo.orderTime.replace(/[^0-9\.\-]/g, '');
    },
  },
  components: {
    pagination
  }
}
